<?php
ignore_user_abort(true);
include './include/common.php';
$file = './cache/mkfile.log';
if(file_exists($file)){
	$data = json_decode(file_get_contents($file),true);
	if($data['u'] !=date('Y-m-d',time()))
	{
		unset($data);
	}
}
if(!isset($data))
{
	$tmp = $db->getone("select count(*) as c from {$table_top}weather");
	$count = $tmp['c'];
	$mydb = getweathertable(date('y',time()));
	$data = array('s'=>0,
	'c'=>$count,
	'u'=>date('Y-m-d'),
	'nowtime'=>time(),
	'stime'=>time(),
	'status'=>false,
	'db'=>$mydb,
	);
}
$s = $data['s'];
$limit = 30;		//每次采集的条数
$db_name = $data['db'];
$list = $db->select("select AreaID from {$table_top}weather limit {$s},{$limit}");

foreach($list as $v)
{
	getcache($v['AreaID'], 'today');
}
$d_s = $s+$limit;
$data['s'] = $d_s;
	$time = $data['nowtime'] - $data['stime'];
	$time = date('i分s秒',$time);
	$data['nowtime'] = time();
	
if($d_s >=$data['c'])
{
	$data['status'] = true;
	file_put_contents($file,json_encode($data));
	exit("文件生成完毕,耗时{$time}");
}else 
{
	
	file_put_contents($file,json_encode($data));
	echo '<meta http-equiv="refresh" content="0;url=?'.time().'">';
	exit('文件正在生成，开始时间'.date('h时i分s秒',$data['stime'])." 现在时间".date('h时i分s秒',$data['nowtime']).",已耗时{$time} <br />总数".$data['c']."条,当前生成第{$s}-".$data['s']."条数据");
}